#include "usart.h"

static int8_t IsDLT645Legal(uint8_t *data,uint8_t len)
{
    uint8_t i,cs;
    int8_t begin = -1;
    
    if(data[len - 1] != 0x16) //end
    {
        return -1;
    }
    
    for(i = 0; i < len; i++) //find first 0x68
    {
        if(data[i] == 0x68)
        {
            begin = i;
            break;
        }
    }
    cs = 0;
    for( i = begin; i < len - 2; i++)
    {
        cs += data[i];
    }
    if(cs != data[len - 2])
    {
        return -1;
    }
        
    return begin;
}


